<template>
  <div class="xiecheng">
    <div class="admin_main_block">
      <div class="admin_main_block_top">
        <div class="admin_main_block_left">
          <div>{{ i18n('organization.view') }}</div>
        </div>

        <div class="admin_main_block_right">
          <div>
            <el-button icon="Back" @click="router.go(-1)">
              {{ i18n('common.return') }}
            </el-button>
          </div>
        </div>
      </div>

      <div class="admin_form_main">
        <el-form label-width="120px" ref="formRef" :model="dataForm" :rules="dataRule">
          <el-card class="box-card" shadow="never">
            <template v-slot:header>
              <div class="clearfix">
                <span>{{ i18n('common.basic_info') }}</span>
              </div>
            </template>
            <div class="text item">
              <el-row>
                <el-col :span="3">
                  <el-image class="logo" v-if="dataForm.logo" :src="dataForm.logo" :lazy="true"></el-image>
                </el-col>
                <el-col :span="21">
                  <el-descriptions border>
                    <el-descriptions-item width="200" :label="i18n('organization.chinese_title')" label-align="right">
                      {{ dataForm.chinese_title }}
                    </el-descriptions-item>
                    <el-descriptions-item width="200" :label="i18n('organization.english_title')" label-align="right" :span="2">
                      {{ dataForm.english_title }}
                    </el-descriptions-item>
                    <el-descriptions-item width="200" :label="i18n('organization.register_limit')" label-align="right">
                      {{ dataForm.register_limit }}
                    </el-descriptions-item>
                    <el-descriptions-item width="200" :label="i18n('organization.valid_time')" label-align="right" :span="2">
                      {{ dataForm.valid_time }}
                    </el-descriptions-item>
                    <el-descriptions-item width="200" :label="i18n('organization.shipowner_id')" label-align="right" :span="3">
                      {{ dataForm.shipowner_name }}
                    </el-descriptions-item>

                    <el-descriptions-item width="200" :label="i18n('organization.inquiry_publish')" label-align="right">
                      {{ dataForm.inquiry_publish }}
                    </el-descriptions-item>
                    <el-descriptions-item width="200" :label="i18n('organization.inquiry_receive')" label-align="right">
                      {{ dataForm.inquiry_receive }}
                    </el-descriptions-item>
                    <el-descriptions-item width="200" :label="i18n('organization.inquiry_valid_time')" label-align="right">
                      {{ dataForm.inquiry_valid_time }}
                    </el-descriptions-item>

                    <el-descriptions-item width="200" :label="i18n('organization.schedule_publish')" label-align="right" :span="3">
                      {{ dataForm.schedule_publish }}
                    </el-descriptions-item>
                    <el-descriptions-item width="200" :label="i18n('organization.create_time')" label-align="right" :span="3">
                      {{ dataForm.create_time }}
                    </el-descriptions-item>
                  </el-descriptions>
                </el-col>
              </el-row>
            </div>
          </el-card>

          <el-card class="box-card mt10" shadow="never">
            <template v-slot:header>
              <div class="clearfix">
                <span>{{ i18n('organization.info') }}</span>
              </div>
            </template>
            <div class="text item">
              <el-descriptions border>
                <el-descriptions-item width="200" :label="i18n('organization.archive.chinese_description')" label-align="right" :span="3">
                  {{ dataForm.chinese_description }}
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('organization.archive.english_description')" label-align="right" :span="3">
                  {{ dataForm.english_description }}
                </el-descriptions-item>
              </el-descriptions>
            </div>
          </el-card>

          <el-card class="box-card mt10" shadow="never">
            <template v-slot:header>
              <div class="clearfix">
                <span>{{ i18n('common.audit_info') }}</span>
              </div>
            </template>
            <div class="text item">
              <el-descriptions border>
                <el-descriptions-item width="200" :label="i18n('common.audit_status')" label-align="right" :span="3">
                  {{ dataForm.audit_status.text }}
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('organization.audit.content')" label-align="right" :span="3">
                  {{ dataForm.audit_content }}
                </el-descriptions-item>
              </el-descriptions>
            </div>
          </el-card>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script setup name="organization-view">
  import { useBase } from "@/hooks/base/useBase"
  import { useForm } from "@/hooks/form/useForm"

  const { router, query, i18n, isAuth } = useBase()

  const model = ref('organization')

  const dataForm = reactive({
    id: 0,
    logo: '',
    chinese_title: '',
    english_title: '',
    shipowner_name: '',
    register_limit: '',
    valid_time: '',
    inquiry_valid_time: '',
    inquiry_publish: '',
    inquiry_receive: '',
    schedule_publish: '',
    audit_status: '',
    audit_content: '',
    create_time: '',
    chinese_description: '',
    english_description: '',
  })

  const dataRule = reactive({})

  const {
    formRef
  } = useForm(model.value, dataForm)

  const init = (form) => {
    dataForm.id = query.id || 0

    nextTick(() => {
      form.value.resetFields()
      if (dataForm.id) {
        $http({
          url: $http.adornUrl(`/${model.value}/view/${dataForm.id}`),
          method: 'get',
          params: $http.adornParams({}),
        }).then(({ data }) => {
          if (data && data.status === 200) {
            dataForm.logo = data.data.logo
            dataForm.chinese_title = data.data.chinese_title
            dataForm.english_title = data.data.english_title
            dataForm.register_limit = data.data.register_limit
            dataForm.valid_time = data.data.valid_time

            dataForm.inquiry_valid_time = data.data.inquiry_valid_time
            dataForm.inquiry_publish = data.data.inquiry_publish.text
            dataForm.inquiry_receive = data.data.inquiry_receive.text
            dataForm.schedule_publish = data.data.schedule_publish.text

            dataForm.audit_status = data.data.audit_status
            dataForm.create_time = data.data.create_time

            if(data.data.shipowner) {
              dataForm.shipowner_name = data.data.shipowner.chinese_name
            }
          }
        }).then(() => {
          if (dataForm.id) {
            $http({
              url: $http.adornUrl(`/${model.value}/archive/data`),
              method: 'get',
              params: $http.adornParams({
                'organization_id': dataForm.id
              }),
            }).then(({ data }) => {
              if (data && data.status === 200) {
                if(data.data) {
                  dataForm.chinese_description = data.data.chinese_description
                  dataForm.english_description = data.data.english_description
                }
              }
            })
          }
        }).then(() => {
          if (dataForm.id) {
            $http({
              url: $http.adornUrl(`/${model.value}/audit/data`),
              method: 'get',
              params: $http.adornParams({
                'organization_id': dataForm.id
              }),
            }).then(({ data }) => {
              if (data && data.status === 200) {
                if(data.data) {
                  dataForm.audit_content = data.data.content
                }
              }
            })
          }
        })
      }
    })
  }

  onMounted(() => {
    init(formRef)
  })
</script>

<style lang="scss" scoped>
  .logo {
    width: 6vw;
    height: 6vw;
    min-width: 120px;
    min-height: 120px;
  }
</style>
